#!/bin/bash

export SRC_DIR=`pwd`

#install rpm build tool
sudo yum install -y rpmdevtools
rpmdev-setuptree

#tpm2-tss install
cd $SRC_DIR
git clone https://gitee.com/src-anolis-os/tpm2-tss.git
cd tpm2-tss/
git checkout a8

cp *.patch ~/rpmbuild/SOURCES/
cp tpm2-tss*.tar.gz ~/rpmbuild/SOURCES/
cp tpm2-tss.spec ~/rpmbuild/SPECS/
cd ~/rpmbuild/SPECS/
rpmbuild -bb tpm2-tss.spec
cd ~/rpmbuild/RPMS/noarch/
sudo rpm -ivh tpm2-tss*.rpm
cd ~/rpmbuild/RPMS/x86_64/
sudo rpm -ivh tpm2-tss*.rpm

#tpm2-abrmd-selinux install
cd $SRC_DIR
git clone https://gitee.com/src-anolis-os/tpm2-abrmd-selinux.git
cd tpm2-abrmd-selinux/
git checkout a8

cp *.patch ~/rpmbuild/SOURCES/
cp tpm2-abrmd*.tar.gz ~/rpmbuild/SOURCES/
cp tpm2-abrmd-selinux.spec ~/rpmbuild/SPECS/
cd ~/rpmbuild/SPECS/
rpmbuild -bb tpm2-abrmd-selinux.spec
cd ~/rpmbuild/RPMS/noarch/
sudo rpm -ivh tpm2-abrmd-selinux*.rpm

#tpm2-abrmd install
cd $SRC_DIR
git clone https://gitee.com/src-anolis-os/tpm2-abrmd.git
cd tpm2-abrmd/
git checkout a8

#get package from github
Name=`cat tpm2-abrmd.spec |grep Name |awk -F ' ' '{print $(NF)}'`
Version=`cat tpm2-abrmd.spec |grep Version |awk -F ' ' '{print $(NF)}'`
wget https://github.com/tpm2-software/tpm2-abrmd/releases/download/${Version}/${Name}-${Version}.tar.gz

cp *.patch ~/rpmbuild/SOURCES/
cp tpm2-abrmd*.tar.gz ~/rpmbuild/SOURCES/
cp tpm2-abrmd.spec ~/rpmbuild/SPECS/
cd ~/rpmbuild/SPECS/
rpmbuild -bb tpm2-abrmd.spec
cd ~/rpmbuild/RPMS/noarch/
sudo rpm -ivh tpm2-abrmd*.rpm
cd ~/rpmbuild/RPMS/x86_64/
sudo rpm -ivh tpm2-abrmd*.rpm

#tpm2-tools install
cd $SRC_DIR
git clone https://gitee.com/src-anolis-os/tpm2-tools.git
cd tpm2-tools/
git checkout a8

cp *.patch ~/rpmbuild/SOURCES/
cp tpm2-tools*.tar.gz ~/rpmbuild/SOURCES/
cp tpm2-tools.spec ~/rpmbuild/SPECS/
cd ~/rpmbuild/SPECS/
rpmbuild -bb tpm2-tools.spec
cd ~/rpmbuild/RPMS/noarch/
sudo rpm -ivh tpm2-tools*.rpm
cd ~/rpmbuild/RPMS/x86_64/
sudo rpm -ivh tpm2-tools*.rpm
